import { createPinia } from 'pinia';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';

// 对缓存数据加密
import type { StorageLike } from 'pinia-plugin-persistedstate';
import SecureLS from 'secure-ls';
// encryptionSecret:自定义密钥
const ls = new SecureLS({
  // isCompression: false,//true压缩 false不压缩
  encryptionSecret: '38c31684-d00d-30dc-82e0-fad9eec46d1d',
  encodingType: 'aes'
});
export const st: StorageLike = {
  setItem(key: string, value: string) {
    ls.set(key, value);
  },
  getItem(key: string): string | null {
    return ls.get(key);
  }
};

// 创建pinia
const pinia = createPinia();
// 数据持久化
pinia.use(piniaPluginPersistedstate);
export default pinia;
